
#region Imported Namespaces
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

using Utility = PHSRAG.Utility;
#endregion

namespace UtilityTest
{
	/// <summary>
	/// The UtilityTest application is a standalone test harness for features provided by the Utility assembly.
	/// </summary>
	public class UtilityTest : Form
	{
		#region Instance Variables
		private Container		components = null;
		private TabPage			cryptTest;
		private TabPage			dataAccessTest;
		private TabPage			exceptionReportTest;
		private TabPage			settingsTest;
		private TabControl		tabs;

		#region Crypt Test Variables
		private Button			decrypt;
		private TextBox			decryptedText;
		private Label			decryptedTextLabel;
		private Button			encrypt;
		private TextBox			encryptedText;
		private Label			encryptedTextLabel;
		private ErrorProvider	errorProvider;
		private TextBox			plainText;
		private Label			plainTextLabel;
		#endregion

		#region Settings Test Variables
		private Button			boolKey;
		private Button			intKey;
		private TextBox			keyName;
		private Label			keyNameLabel;
		private TextBox			keyValue;
		private Label			keyValueLabel;
		private Label			selectLabel;
		private Button			stringKey;
		#endregion

		#region DataAccess Test Variables
		private TextBox			connectionString;
		private Label			connectionStringLabel;
		private Button			createConnectionString;
		private Button			invokeSproc;
		private Button			loadSprocList;
		private ComboBox		sprocList;
		private Label			sprocListLabel;
		#endregion

		#region ExceptionReport Test Variables
		private TextBox			eventLogText;
		private Label			eventLogTextLabel;
		private ComboBox		eventLogReportType;
		private Label			eventLogReportTypeLabel;
		private CheckBox		includeStackTrace;
		private SaveFileDialog	saveFileDialog;
		private Button			writeExceptionToEventLog;
		private Button			writeExceptionToFile;
		private Button			writeStringToEventLog;
		#endregion

		#region SortedHashList Test Variables
		private TabPage			sortedHashListTest;
		private Button			add;
		private Label			sortedHashListValueLabel;
		private Label			sortedHashListKeyLabel;
		private Label			enterSortedHashListLabel;
		private TextBox			sortedHashListValue;
		private TextBox			sortedHashListKey;
		private Button			writeStringToFile;
		private System.Windows.Forms.Button iterateSortedHashCount;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label iterateSortedHashTableResults;

		private Utility.SortedHashList sortedHashList;
		#endregion
		#endregion

		#region Constructor
		public UtilityTest()
		{
			InitializeComponent();
		}
		#endregion

		#region Overrides
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
				components.Dispose();
			base.Dispose(disposing);
		}
		#endregion

		#region Utility Test Event Handlers
		private void OnDecrypt(object sender, System.EventArgs e)
		{
			string inputString = encryptedText.Text.Trim();
			if (inputString.Length == 0)
				errorProvider.SetError(encryptedText, "You must specify a string");
			else
			{
				errorProvider.SetError(encryptedText, "");
				decryptedText.Text = Utility.Crypt.DecryptFromString(inputString);
			}
		}

		private void OnEncrypt(object sender, System.EventArgs e)
		{
			string inputString = plainText.Text.Trim();
			if (inputString.Length == 0)
				errorProvider.SetError(plainText, "You must specify a string");
			else
			{
				errorProvider.SetError(plainText, "");
				encryptedText.Text = Utility.Crypt.EncryptToString(inputString);
			}
		}
		#endregion

		#region Settings Test Event Handlers
		private void OnGetBoolKeyValue(object sender, System.EventArgs e)
		{
			keyName.Text = "BoolKey";
			keyValue.Text = Utility.Settings.GetKeyValue(keyName.Text, "");
		}

		private void OnGetIntKeyValue(object sender, System.EventArgs e)
		{
			keyName.Text = "IntKey";
			keyValue.Text = Utility.Settings.GetKeyValue(keyName.Text, "");
		}

		private void OnGetStringKeyValue(object sender, System.EventArgs e)
		{
			keyName.Text = "StringKey";
			keyValue.Text = Utility.Settings.GetKeyValue(keyName.Text, "");
		}
		#endregion

		#region DataAccess Test Event Handlers
		private void OnCreateConnectionString(object sender, System.EventArgs e)
		{
			ADODB._Connection connection = (ADODB._Connection)(new MSDASC.DataLinksClass()).PromptNew();
			if (connection != null)
				connectionString.Text = connection.ConnectionString.Trim();
		}

		private void OnInvokeSproc(object sender, System.EventArgs e)
		{
			string normalizedConnectionString = Utility.DataAccess.NormalizeConnectionString(connectionString.Text);
			string sprocName = sprocList.SelectedItem.ToString();

			SprocParameters sp = new SprocParameters(normalizedConnectionString, sprocName);
			if (sp.ShowDialog(this) == DialogResult.OK)
			{
				DataSet ds = Utility.DataAccess.GetDataSet(normalizedConnectionString, sprocName, sp.Parameters);
				SprocResult sr = new SprocResult(ds);
				sr.ShowDialog(this);
			}
		}

		private void OnLoadSprocList(object sender, System.EventArgs e)
		{
			SqlConnection connection = new SqlConnection(Utility.DataAccess.NormalizeConnectionString(connectionString.Text));
			try
			{
				connection.Open();
				SqlCommand command = new SqlCommand();
				command.Connection = connection;
				command.CommandType = CommandType.Text;
				command.CommandText = @"select specific_name from information_schema.routines where routine_type = 'procedure' order by specific_name";

				SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
				while (reader.Read())
					sprocList.Items.Add(reader[0]);
				reader.Close();

				if (sprocList.Items.Count > 0)
					sprocList.SelectedIndex = 0;
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Failed to load stored procedure list", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
			finally
			{
				if (connection.State != ConnectionState.Closed)
					connection.Close();
			}
		}
		#endregion

		#region ExceptionReport Test Event Handlers
		private void OnWriteExceptionToEventLog(object sender, System.EventArgs e)
		{
			try
			{
				try
				{
					throw new Exception("Exception 1");
				}
				catch (Exception e1)
				{
					throw new Exception("Exception 2", e1);
				}
			}
			catch (Exception e2)
			{
				Utility.ExceptionReport.WriteToEventLog("UtilityTest", e2, includeStackTrace.Checked,
					GetReportType(eventLogReportType.SelectedItem.ToString()));
			}
		}

		private void OnWriteExceptionToFile(object sender, System.EventArgs e)
		{
			if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
			{
				try
				{
					try
					{
						throw new Exception("Exception 1");
					}
					catch (Exception e1)
					{
						throw new Exception("Exception 2", e1);
					}
				}
				catch (Exception e2)
				{
					Utility.ExceptionReport.WriteToFile("UtilityTest", e2, includeStackTrace.Checked,
						GetReportType(eventLogReportType.SelectedItem.ToString()), saveFileDialog.FileName);
				}
			}
		}

		private void OnWriteStringToEventLog(object sender, System.EventArgs e)
		{
			string text = eventLogText.Text.Trim();
			if (text.Length == 0)
				errorProvider.SetError(eventLogText, "You must specify some text to write");
			else
			{
				errorProvider.SetError(eventLogText, "");
				Utility.ExceptionReport.WriteToEventLog("UtilityTest", text, GetReportType(eventLogReportType.SelectedItem.ToString()));
			}
		}

		private void OnWriteStringToFile(object sender, System.EventArgs e)
		{
			string text = eventLogText.Text.Trim();
			if (text.Length == 0)
				errorProvider.SetError(eventLogText, "You must specify some text to write");
			else
			{
				errorProvider.SetError(eventLogText, "");
				if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
					Utility.ExceptionReport.WriteToFile("UtilityTest", text, GetReportType(eventLogReportType.SelectedItem.ToString()), saveFileDialog.FileName);
			}
		}
		#endregion

		#region Event Handlers
		private void OnLoad(object sender, System.EventArgs e)
		{
			tabs.SelectedIndex = tabs.TabCount - 1;
			tabs.SelectedIndex = 0;
		}

		private void OnTabChanged(object sender, System.EventArgs e)
		{
			if (tabs.SelectedTab == cryptTest)
				plainText.Focus();
			else if (tabs.SelectedTab == settingsTest)
				stringKey.Focus();
			else if (tabs.SelectedTab == dataAccessTest)
				connectionString.Focus();
			else if (tabs.SelectedTab == exceptionReportTest)
			{
				eventLogText.Focus();
				eventLogReportType.SelectedIndex = 0;
			}
		}
		#endregion

		#region Private Methods
		#region ExceptionReport Test Methods
		private Utility.ExceptionReport.ReportType GetReportType(string typeName)
		{
			switch (eventLogReportType.SelectedItem.ToString())
			{
				case "Warning": return Utility.ExceptionReport.ReportType.Warning;
				case "Error": return Utility.ExceptionReport.ReportType.Error;
				default: return Utility.ExceptionReport.ReportType.Information;
			}
		}
		#endregion
		#endregion

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.tabs = new System.Windows.Forms.TabControl();
			this.cryptTest = new System.Windows.Forms.TabPage();
			this.decryptedText = new System.Windows.Forms.TextBox();
			this.decryptedTextLabel = new System.Windows.Forms.Label();
			this.decrypt = new System.Windows.Forms.Button();
			this.encryptedText = new System.Windows.Forms.TextBox();
			this.encryptedTextLabel = new System.Windows.Forms.Label();
			this.encrypt = new System.Windows.Forms.Button();
			this.plainText = new System.Windows.Forms.TextBox();
			this.plainTextLabel = new System.Windows.Forms.Label();
			this.dataAccessTest = new System.Windows.Forms.TabPage();
			this.invokeSproc = new System.Windows.Forms.Button();
			this.loadSprocList = new System.Windows.Forms.Button();
			this.sprocList = new System.Windows.Forms.ComboBox();
			this.sprocListLabel = new System.Windows.Forms.Label();
			this.createConnectionString = new System.Windows.Forms.Button();
			this.connectionString = new System.Windows.Forms.TextBox();
			this.connectionStringLabel = new System.Windows.Forms.Label();
			this.settingsTest = new System.Windows.Forms.TabPage();
			this.keyValue = new System.Windows.Forms.TextBox();
			this.keyName = new System.Windows.Forms.TextBox();
			this.keyValueLabel = new System.Windows.Forms.Label();
			this.keyNameLabel = new System.Windows.Forms.Label();
			this.boolKey = new System.Windows.Forms.Button();
			this.intKey = new System.Windows.Forms.Button();
			this.stringKey = new System.Windows.Forms.Button();
			this.selectLabel = new System.Windows.Forms.Label();
			this.exceptionReportTest = new System.Windows.Forms.TabPage();
			this.includeStackTrace = new System.Windows.Forms.CheckBox();
			this.writeStringToFile = new System.Windows.Forms.Button();
			this.eventLogReportType = new System.Windows.Forms.ComboBox();
			this.eventLogReportTypeLabel = new System.Windows.Forms.Label();
			this.writeStringToEventLog = new System.Windows.Forms.Button();
			this.eventLogText = new System.Windows.Forms.TextBox();
			this.eventLogTextLabel = new System.Windows.Forms.Label();
			this.writeExceptionToEventLog = new System.Windows.Forms.Button();
			this.writeExceptionToFile = new System.Windows.Forms.Button();
			this.sortedHashListTest = new System.Windows.Forms.TabPage();
			this.iterateSortedHashTableResults = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.iterateSortedHashCount = new System.Windows.Forms.Button();
			this.sortedHashListValueLabel = new System.Windows.Forms.Label();
			this.sortedHashListKeyLabel = new System.Windows.Forms.Label();
			this.enterSortedHashListLabel = new System.Windows.Forms.Label();
			this.sortedHashListValue = new System.Windows.Forms.TextBox();
			this.add = new System.Windows.Forms.Button();
			this.sortedHashListKey = new System.Windows.Forms.TextBox();
			this.errorProvider = new System.Windows.Forms.ErrorProvider();
			this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
			this.tabs.SuspendLayout();
			this.cryptTest.SuspendLayout();
			this.dataAccessTest.SuspendLayout();
			this.settingsTest.SuspendLayout();
			this.exceptionReportTest.SuspendLayout();
			this.sortedHashListTest.SuspendLayout();
			this.SuspendLayout();
			// 
			// tabs
			// 
			this.tabs.Controls.Add(this.cryptTest);
			this.tabs.Controls.Add(this.exceptionReportTest);
			this.tabs.Controls.Add(this.settingsTest);
			this.tabs.Controls.Add(this.dataAccessTest);
			this.tabs.Controls.Add(this.sortedHashListTest);
			this.tabs.Dock = System.Windows.Forms.DockStyle.Fill;
			this.tabs.Location = new System.Drawing.Point(0, 0);
			this.tabs.Multiline = true;
			this.tabs.Name = "tabs";
			this.tabs.SelectedIndex = 0;
			this.tabs.Size = new System.Drawing.Size(466, 279);
			this.tabs.TabIndex = 0;
			this.tabs.SelectedIndexChanged += new System.EventHandler(this.OnTabChanged);
			// 
			// cryptTest
			// 
			this.cryptTest.Controls.Add(this.decryptedText);
			this.cryptTest.Controls.Add(this.decryptedTextLabel);
			this.cryptTest.Controls.Add(this.decrypt);
			this.cryptTest.Controls.Add(this.encryptedText);
			this.cryptTest.Controls.Add(this.encryptedTextLabel);
			this.cryptTest.Controls.Add(this.encrypt);
			this.cryptTest.Controls.Add(this.plainText);
			this.cryptTest.Controls.Add(this.plainTextLabel);
			this.cryptTest.Location = new System.Drawing.Point(4, 22);
			this.cryptTest.Name = "cryptTest";
			this.cryptTest.Size = new System.Drawing.Size(458, 253);
			this.cryptTest.TabIndex = 0;
			this.cryptTest.Text = "Crypt Test";
			this.cryptTest.ToolTipText = "Conduct test on the Crypt class";
			// 
			// decryptedText
			// 
			this.decryptedText.Location = new System.Drawing.Point(9, 220);
			this.decryptedText.Name = "decryptedText";
			this.decryptedText.ReadOnly = true;
			this.decryptedText.Size = new System.Drawing.Size(368, 20);
			this.decryptedText.TabIndex = 7;
			this.decryptedText.TabStop = false;
			this.decryptedText.Text = "";
			// 
			// decryptedTextLabel
			// 
			this.decryptedTextLabel.Location = new System.Drawing.Point(9, 195);
			this.decryptedTextLabel.Name = "decryptedTextLabel";
			this.decryptedTextLabel.Size = new System.Drawing.Size(160, 23);
			this.decryptedTextLabel.TabIndex = 6;
			this.decryptedTextLabel.Text = "Decrypted string:";
			// 
			// decrypt
			// 
			this.decrypt.Location = new System.Drawing.Point(9, 159);
			this.decrypt.Name = "decrypt";
			this.decrypt.TabIndex = 3;
			this.decrypt.Text = "Decrypt";
			this.decrypt.Click += new System.EventHandler(this.OnDecrypt);
			// 
			// encryptedText
			// 
			this.encryptedText.Location = new System.Drawing.Point(9, 129);
			this.encryptedText.Name = "encryptedText";
			this.encryptedText.Size = new System.Drawing.Size(368, 20);
			this.encryptedText.TabIndex = 2;
			this.encryptedText.Text = "";
			// 
			// encryptedTextLabel
			// 
			this.encryptedTextLabel.Location = new System.Drawing.Point(9, 104);
			this.encryptedTextLabel.Name = "encryptedTextLabel";
			this.encryptedTextLabel.Size = new System.Drawing.Size(160, 23);
			this.encryptedTextLabel.TabIndex = 3;
			this.encryptedTextLabel.Text = "Enter string to be decrypted:";
			// 
			// encrypt
			// 
			this.encrypt.Location = new System.Drawing.Point(9, 63);
			this.encrypt.Name = "encrypt";
			this.encrypt.TabIndex = 1;
			this.encrypt.Text = "Encrypt";
			this.encrypt.Click += new System.EventHandler(this.OnEncrypt);
			// 
			// plainText
			// 
			this.plainText.Location = new System.Drawing.Point(9, 33);
			this.plainText.Name = "plainText";
			this.plainText.Size = new System.Drawing.Size(368, 20);
			this.plainText.TabIndex = 0;
			this.plainText.Text = "";
			// 
			// plainTextLabel
			// 
			this.plainTextLabel.Location = new System.Drawing.Point(9, 8);
			this.plainTextLabel.Name = "plainTextLabel";
			this.plainTextLabel.Size = new System.Drawing.Size(160, 23);
			this.plainTextLabel.TabIndex = 0;
			this.plainTextLabel.Text = "Enter string to be encrypted:";
			// 
			// dataAccessTest
			// 
			this.dataAccessTest.Controls.Add(this.invokeSproc);
			this.dataAccessTest.Controls.Add(this.loadSprocList);
			this.dataAccessTest.Controls.Add(this.sprocList);
			this.dataAccessTest.Controls.Add(this.sprocListLabel);
			this.dataAccessTest.Controls.Add(this.createConnectionString);
			this.dataAccessTest.Controls.Add(this.connectionString);
			this.dataAccessTest.Controls.Add(this.connectionStringLabel);
			this.dataAccessTest.Location = new System.Drawing.Point(4, 22);
			this.dataAccessTest.Name = "dataAccessTest";
			this.dataAccessTest.Size = new System.Drawing.Size(458, 253);
			this.dataAccessTest.TabIndex = 2;
			this.dataAccessTest.Text = "DataAccess Test";
			this.dataAccessTest.ToolTipText = "Conduct tests on the DataAccess class";
			// 
			// invokeSproc
			// 
			this.invokeSproc.Location = new System.Drawing.Point(11, 142);
			this.invokeSproc.Name = "invokeSproc";
			this.invokeSproc.Size = new System.Drawing.Size(185, 23);
			this.invokeSproc.TabIndex = 4;
			this.invokeSproc.Text = "Invoke Stored Procedure";
			this.invokeSproc.Click += new System.EventHandler(this.OnInvokeSproc);
			// 
			// loadSprocList
			// 
			this.loadSprocList.Location = new System.Drawing.Point(11, 60);
			this.loadSprocList.Name = "loadSprocList";
			this.loadSprocList.Size = new System.Drawing.Size(185, 23);
			this.loadSprocList.TabIndex = 2;
			this.loadSprocList.Text = "Load Stored Procedure List";
			this.loadSprocList.Click += new System.EventHandler(this.OnLoadSprocList);
			// 
			// sprocList
			// 
			this.sprocList.Location = new System.Drawing.Point(10, 109);
			this.sprocList.Name = "sprocList";
			this.sprocList.Size = new System.Drawing.Size(369, 21);
			this.sprocList.TabIndex = 3;
			// 
			// sprocListLabel
			// 
			this.sprocListLabel.Location = new System.Drawing.Point(10, 87);
			this.sprocListLabel.Name = "sprocListLabel";
			this.sprocListLabel.Size = new System.Drawing.Size(174, 23);
			this.sprocListLabel.TabIndex = 2;
			this.sprocListLabel.Text = "Select stored procedure name:";
			// 
			// createConnectionString
			// 
			this.createConnectionString.Location = new System.Drawing.Point(304, 29);
			this.createConnectionString.Name = "createConnectionString";
			this.createConnectionString.Size = new System.Drawing.Size(74, 23);
			this.createConnectionString.TabIndex = 1;
			this.createConnectionString.Text = "Create...";
			this.createConnectionString.Click += new System.EventHandler(this.OnCreateConnectionString);
			// 
			// connectionString
			// 
			this.connectionString.Location = new System.Drawing.Point(10, 30);
			this.connectionString.Name = "connectionString";
			this.connectionString.Size = new System.Drawing.Size(286, 20);
			this.connectionString.TabIndex = 0;
			this.connectionString.Text = "";
			// 
			// connectionStringLabel
			// 
			this.connectionStringLabel.Location = new System.Drawing.Point(10, 8);
			this.connectionStringLabel.Name = "connectionStringLabel";
			this.connectionStringLabel.Size = new System.Drawing.Size(266, 23);
			this.connectionStringLabel.TabIndex = 0;
			this.connectionStringLabel.Text = "Specify connection string (or click Create...):";
			// 
			// settingsTest
			// 
			this.settingsTest.Controls.Add(this.keyValue);
			this.settingsTest.Controls.Add(this.keyName);
			this.settingsTest.Controls.Add(this.keyValueLabel);
			this.settingsTest.Controls.Add(this.keyNameLabel);
			this.settingsTest.Controls.Add(this.boolKey);
			this.settingsTest.Controls.Add(this.intKey);
			this.settingsTest.Controls.Add(this.stringKey);
			this.settingsTest.Controls.Add(this.selectLabel);
			this.settingsTest.Location = new System.Drawing.Point(4, 22);
			this.settingsTest.Name = "settingsTest";
			this.settingsTest.Size = new System.Drawing.Size(458, 253);
			this.settingsTest.TabIndex = 1;
			this.settingsTest.Text = "Settings Test";
			this.settingsTest.ToolTipText = "Conduct tests on the Settings class";
			// 
			// keyValue
			// 
			this.keyValue.Location = new System.Drawing.Point(105, 104);
			this.keyValue.Name = "keyValue";
			this.keyValue.ReadOnly = true;
			this.keyValue.Size = new System.Drawing.Size(174, 20);
			this.keyValue.TabIndex = 2;
			this.keyValue.TabStop = false;
			this.keyValue.Text = "";
			// 
			// keyName
			// 
			this.keyName.Location = new System.Drawing.Point(105, 76);
			this.keyName.Name = "keyName";
			this.keyName.ReadOnly = true;
			this.keyName.Size = new System.Drawing.Size(174, 20);
			this.keyName.TabIndex = 6;
			this.keyName.TabStop = false;
			this.keyName.Text = "";
			// 
			// keyValueLabel
			// 
			this.keyValueLabel.Location = new System.Drawing.Point(15, 103);
			this.keyValueLabel.Name = "keyValueLabel";
			this.keyValueLabel.Size = new System.Drawing.Size(73, 23);
			this.keyValueLabel.TabIndex = 5;
			this.keyValueLabel.Text = "Key value:";
			this.keyValueLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// keyNameLabel
			// 
			this.keyNameLabel.Location = new System.Drawing.Point(15, 75);
			this.keyNameLabel.Name = "keyNameLabel";
			this.keyNameLabel.Size = new System.Drawing.Size(73, 23);
			this.keyNameLabel.TabIndex = 4;
			this.keyNameLabel.Text = "Key name:";
			this.keyNameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// boolKey
			// 
			this.boolKey.Location = new System.Drawing.Point(279, 37);
			this.boolKey.Name = "boolKey";
			this.boolKey.TabIndex = 3;
			this.boolKey.Text = "Boolean";
			this.boolKey.Click += new System.EventHandler(this.OnGetBoolKeyValue);
			// 
			// intKey
			// 
			this.intKey.Location = new System.Drawing.Point(156, 36);
			this.intKey.Name = "intKey";
			this.intKey.TabIndex = 1;
			this.intKey.Text = "Integer";
			this.intKey.Click += new System.EventHandler(this.OnGetIntKeyValue);
			// 
			// stringKey
			// 
			this.stringKey.Location = new System.Drawing.Point(33, 36);
			this.stringKey.Name = "stringKey";
			this.stringKey.TabIndex = 0;
			this.stringKey.Text = "String";
			this.stringKey.Click += new System.EventHandler(this.OnGetStringKeyValue);
			// 
			// selectLabel
			// 
			this.selectLabel.Location = new System.Drawing.Point(15, 8);
			this.selectLabel.Name = "selectLabel";
			this.selectLabel.Size = new System.Drawing.Size(253, 23);
			this.selectLabel.TabIndex = 0;
			this.selectLabel.Text = "Click on a button to get value of that key:";
			// 
			// exceptionReportTest
			// 
			this.exceptionReportTest.Controls.Add(this.includeStackTrace);
			this.exceptionReportTest.Controls.Add(this.writeStringToFile);
			this.exceptionReportTest.Controls.Add(this.eventLogReportType);
			this.exceptionReportTest.Controls.Add(this.eventLogReportTypeLabel);
			this.exceptionReportTest.Controls.Add(this.writeStringToEventLog);
			this.exceptionReportTest.Controls.Add(this.eventLogText);
			this.exceptionReportTest.Controls.Add(this.eventLogTextLabel);
			this.exceptionReportTest.Controls.Add(this.writeExceptionToEventLog);
			this.exceptionReportTest.Controls.Add(this.writeExceptionToFile);
			this.exceptionReportTest.Location = new System.Drawing.Point(4, 22);
			this.exceptionReportTest.Name = "exceptionReportTest";
			this.exceptionReportTest.Size = new System.Drawing.Size(458, 253);
			this.exceptionReportTest.TabIndex = 3;
			this.exceptionReportTest.Text = "ExceptionReport Test";
			// 
			// includeStackTrace
			// 
			this.includeStackTrace.Location = new System.Drawing.Point(240, 185);
			this.includeStackTrace.Name = "includeStackTrace";
			this.includeStackTrace.Size = new System.Drawing.Size(129, 24);
			this.includeStackTrace.TabIndex = 5;
			this.includeStackTrace.Text = "Include Stack Trace";
			// 
			// writeStringToFile
			// 
			this.writeStringToFile.Location = new System.Drawing.Point(10, 131);
			this.writeStringToFile.Name = "writeStringToFile";
			this.writeStringToFile.Size = new System.Drawing.Size(222, 23);
			this.writeStringToFile.TabIndex = 4;
			this.writeStringToFile.Text = "Write String To File ...";
			this.writeStringToFile.Click += new System.EventHandler(this.OnWriteStringToFile);
			// 
			// eventLogReportType
			// 
			this.eventLogReportType.Items.AddRange(new object[] {
																	"Information",
																	"Warning",
																	"Error"});
			this.eventLogReportType.Location = new System.Drawing.Point(111, 61);
			this.eventLogReportType.Name = "eventLogReportType";
			this.eventLogReportType.Size = new System.Drawing.Size(121, 21);
			this.eventLogReportType.TabIndex = 1;
			// 
			// eventLogReportTypeLabel
			// 
			this.eventLogReportTypeLabel.Location = new System.Drawing.Point(9, 63);
			this.eventLogReportTypeLabel.Name = "eventLogReportTypeLabel";
			this.eventLogReportTypeLabel.TabIndex = 3;
			this.eventLogReportTypeLabel.Text = "Select report type:";
			// 
			// writeStringToEventLog
			// 
			this.writeStringToEventLog.Location = new System.Drawing.Point(10, 101);
			this.writeStringToEventLog.Name = "writeStringToEventLog";
			this.writeStringToEventLog.Size = new System.Drawing.Size(222, 23);
			this.writeStringToEventLog.TabIndex = 2;
			this.writeStringToEventLog.Text = "Write String To Application Event Log";
			this.writeStringToEventLog.Click += new System.EventHandler(this.OnWriteStringToEventLog);
			// 
			// eventLogText
			// 
			this.eventLogText.Location = new System.Drawing.Point(9, 30);
			this.eventLogText.Name = "eventLogText";
			this.eventLogText.Size = new System.Drawing.Size(360, 20);
			this.eventLogText.TabIndex = 0;
			this.eventLogText.Text = "";
			// 
			// eventLogTextLabel
			// 
			this.eventLogTextLabel.Location = new System.Drawing.Point(9, 8);
			this.eventLogTextLabel.Name = "eventLogTextLabel";
			this.eventLogTextLabel.Size = new System.Drawing.Size(306, 23);
			this.eventLogTextLabel.TabIndex = 0;
			this.eventLogTextLabel.Text = "Enter string to write to the Application Event Log:";
			// 
			// writeExceptionToEventLog
			// 
			this.writeExceptionToEventLog.Location = new System.Drawing.Point(10, 170);
			this.writeExceptionToEventLog.Name = "writeExceptionToEventLog";
			this.writeExceptionToEventLog.Size = new System.Drawing.Size(222, 23);
			this.writeExceptionToEventLog.TabIndex = 2;
			this.writeExceptionToEventLog.Text = "Write Exception To Application Event Log";
			this.writeExceptionToEventLog.Click += new System.EventHandler(this.OnWriteExceptionToEventLog);
			// 
			// writeExceptionToFile
			// 
			this.writeExceptionToFile.Location = new System.Drawing.Point(10, 201);
			this.writeExceptionToFile.Name = "writeExceptionToFile";
			this.writeExceptionToFile.Size = new System.Drawing.Size(222, 23);
			this.writeExceptionToFile.TabIndex = 4;
			this.writeExceptionToFile.Text = "Write Exception To File ...";
			this.writeExceptionToFile.Click += new System.EventHandler(this.OnWriteExceptionToFile);
			// 
			// sortedHashListTest
			// 
			this.sortedHashListTest.Controls.Add(this.iterateSortedHashTableResults);
			this.sortedHashListTest.Controls.Add(this.label1);
			this.sortedHashListTest.Controls.Add(this.iterateSortedHashCount);
			this.sortedHashListTest.Controls.Add(this.sortedHashListValueLabel);
			this.sortedHashListTest.Controls.Add(this.sortedHashListKeyLabel);
			this.sortedHashListTest.Controls.Add(this.enterSortedHashListLabel);
			this.sortedHashListTest.Controls.Add(this.sortedHashListValue);
			this.sortedHashListTest.Controls.Add(this.add);
			this.sortedHashListTest.Controls.Add(this.sortedHashListKey);
			this.sortedHashListTest.Location = new System.Drawing.Point(4, 22);
			this.sortedHashListTest.Name = "sortedHashListTest";
			this.sortedHashListTest.Size = new System.Drawing.Size(458, 253);
			this.sortedHashListTest.TabIndex = 4;
			this.sortedHashListTest.Text = "sorted HashListTest";
			// 
			// iterateSortedHashTableResults
			// 
			this.iterateSortedHashTableResults.Location = new System.Drawing.Point(112, 104);
			this.iterateSortedHashTableResults.Name = "iterateSortedHashTableResults";
			this.iterateSortedHashTableResults.Size = new System.Drawing.Size(320, 23);
			this.iterateSortedHashTableResults.TabIndex = 11;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 80);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(200, 23);
			this.label1.TabIndex = 10;
			this.label1.Text = "Iterate through the Sorted Hash List";
			// 
			// iterateSortedHashCount
			// 
			this.iterateSortedHashCount.Location = new System.Drawing.Point(8, 104);
			this.iterateSortedHashCount.Name = "iterateSortedHashCount";
			this.iterateSortedHashCount.TabIndex = 9;
			this.iterateSortedHashCount.Text = "Iterate";
			this.iterateSortedHashCount.Click += new System.EventHandler(this.OnIterate);
			// 
			// sortedHashListValueLabel
			// 
			this.sortedHashListValueLabel.Location = new System.Drawing.Point(192, 24);
			this.sortedHashListValueLabel.Name = "sortedHashListValueLabel";
			this.sortedHashListValueLabel.Size = new System.Drawing.Size(40, 16);
			this.sortedHashListValueLabel.TabIndex = 5;
			this.sortedHashListValueLabel.Text = "Value: ";
			// 
			// sortedHashListKeyLabel
			// 
			this.sortedHashListKeyLabel.Location = new System.Drawing.Point(8, 24);
			this.sortedHashListKeyLabel.Name = "sortedHashListKeyLabel";
			this.sortedHashListKeyLabel.Size = new System.Drawing.Size(40, 40);
			this.sortedHashListKeyLabel.TabIndex = 4;
			this.sortedHashListKeyLabel.Text = "Key (must be int):";
			// 
			// enterSortedHashListLabel
			// 
			this.enterSortedHashListLabel.Location = new System.Drawing.Point(8, 8);
			this.enterSortedHashListLabel.Name = "enterSortedHashListLabel";
			this.enterSortedHashListLabel.Size = new System.Drawing.Size(160, 16);
			this.enterSortedHashListLabel.TabIndex = 3;
			this.enterSortedHashListLabel.Text = "Enter Sorted Hash List Items";
			// 
			// sortedHashListValue
			// 
			this.sortedHashListValue.Location = new System.Drawing.Point(240, 24);
			this.sortedHashListValue.Name = "sortedHashListValue";
			this.sortedHashListValue.TabIndex = 2;
			this.sortedHashListValue.Text = "";
			// 
			// add
			// 
			this.add.Location = new System.Drawing.Point(368, 24);
			this.add.Name = "add";
			this.add.TabIndex = 1;
			this.add.Text = "Add";
			this.add.Click += new System.EventHandler(this.OnAdd);
			// 
			// sortedHashListKey
			// 
			this.sortedHashListKey.Location = new System.Drawing.Point(72, 24);
			this.sortedHashListKey.Name = "sortedHashListKey";
			this.sortedHashListKey.TabIndex = 0;
			this.sortedHashListKey.Text = "";
			// 
			// errorProvider
			// 
			this.errorProvider.BlinkStyle = System.Windows.Forms.ErrorBlinkStyle.AlwaysBlink;
			this.errorProvider.ContainerControl = this;
			// 
			// saveFileDialog
			// 
			this.saveFileDialog.DefaultExt = "log";
			this.saveFileDialog.FileName = "UtilityTest.log";
			this.saveFileDialog.Filter = "Log Files|*.log";
			this.saveFileDialog.OverwritePrompt = false;
			this.saveFileDialog.RestoreDirectory = true;
			this.saveFileDialog.Title = "Select Log File";
			// 
			// UtilityTest
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(466, 279);
			this.Controls.Add(this.tabs);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "UtilityTest";
			this.Text = "UtilityTest";
			this.Load += new System.EventHandler(this.OnLoad);
			this.tabs.ResumeLayout(false);
			this.cryptTest.ResumeLayout(false);
			this.dataAccessTest.ResumeLayout(false);
			this.settingsTest.ResumeLayout(false);
			this.exceptionReportTest.ResumeLayout(false);
			this.sortedHashListTest.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		#region Entry Point
		[STAThread]
		static void Main() 
		{
			Application.Run(new UtilityTest());
		}
		#endregion

		private void OnAdd(object sender, System.EventArgs e)
		{
			iterateSortedHashTableResults.Text = "";
			if (this.sortedHashList == null)
			{
				sortedHashList = new PHSRAG.Utility.SortedHashList();
			}

			string key = sortedHashListKey.Text.Trim();
			string value = sortedHashListValue.Text.Trim();

			if ( (key.Length > 0) && (value.Length > 0))
			{
				sortedHashList.Add(Convert.ToInt32(key), value);
			}
			else
				MessageBox.Show(this, "Valid values must be specified for Key and Value fields.",
					"Unable to add Key and Value to Sorted Hash List",
					MessageBoxButtons.OK, 
					MessageBoxIcon.Error);



			sortedHashListKey.Text = "";
			sortedHashListValue.Text = "";



		}

		private void OnIterate(object sender, System.EventArgs e)
		{
			if (this.sortedHashList == null)
			{
				iterateSortedHashTableResults.Text = "No entries to iterate.";
			}
			else
			{
				int i = 0;
				foreach(string s in sortedHashList)
				{
					++i;
				}
				iterateSortedHashTableResults.Text = 
					String.Format("There are {0} items in the Sorted Hash List",
					Convert.ToString(i));
			}
		}
	}
}
